package com.ybox.app.api.factory;

import com.ybox.app.api.domain.AppCollectArticle;
import com.ybox.app.api.service.RemoteAppCollectArticleService;
import com.ybox.common.core.web.domain.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 文件服务降级处理
 *
 * @author ych
 */
@Component
public class RemoteAppCollectArticleFallbackFactory implements FallbackFactory<RemoteAppCollectArticleService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteAppCollectArticleFallbackFactory.class);

    @Override
    public RemoteAppCollectArticleService create(Throwable throwable) {
        log.error("APP服务调用失败:{}", throwable.getMessage());
        return new RemoteAppCollectArticleService() {
            @Override
            public AjaxResult queryById(String id) {
                return AjaxResult.error("查询文章失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult addInner(AppCollectArticle appCollectArticle, String source) {
                return AjaxResult.error("添加文章失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult edit(AppCollectArticle appCollectArticle) {
                return AjaxResult.error("修改文章失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult remove(String[] collectIds) {
                return AjaxResult.error("删除文章失败:" + throwable.getMessage());
            }
        };
    }
}
